package com.admission.aop;

import org.apache.commons.lang.xwork.StringUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.admission.model.Log;
import com.admission.service.LogManager;

@Aspect
@Component
public class CommonAop {

	private LogManager logManager;

	@AfterThrowing(value = "execution(* com.admission.*.*.*(..))", throwing = "ex")
	public void doErrorAction(JoinPoint joinPoint, Throwable ex) {
		Log l = new Log();
		l.setMessage(StringUtils.isEmpty(ex.getMessage()) ? "系统发生未知错误，请与开发人员联系，错误信息"
				+ ex.toString()
				: ex.getMessage());
		l.setMethod(joinPoint.getSignature().toString());

		logManager.save(l);
	}

	@Autowired
	public void setLogManager(LogManager logManager) {
		this.logManager = logManager;
	}

}
